#include <iostream>
#include <cassert>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"

using namespace std;

int main()
{
    // 打开管道文件 --- 只写
    int wfd = open(fifo_name.c_str(), O_WRONLY);
    assert(wfd != -1);
    (void)wfd;

    char buff[64];
    while (true)
    {
        cout << "远程发送指令:> ";
        fgets(buff, sizeof(buff) - 1, stdin);
        buff[strlen(buff) - 1] = '\0';  // 去除 '\n'

        if (strcasecmp("exit", buff) == 0)
            break;

        // 向管道写入数据
        write(wfd, buff, strlen(buff));
    }

    close(wfd);
    return 0;
}